home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 422_02 / dosutil / ecomchk.asm < prev    next >
Assembly Source File  |  1994-03-20  |  1KB  |  47 lines

  1. ;
  2. ; Embedded function for the COMCHK utility.
  3. ;
  4. ; Copyright 1990-1994 Dave Dunfield.
  5. ;
  6. ; May be freely distributed and used as long as
  7. ; my copyright notices are retained.
  8. ;
  9. DGRP    GROUP    DSEG
  10. DSEG    SEGMENT    BYTE PUBLIC 'IDATA'
  11. DSEG    ENDS
  12. CSEG    SEGMENT    BYTE PUBLIC 'CODE'
  13.         ASSUME    CS:CSEG, DS:DGRP, SS:DGRP
  14.         PUBLIC    _CHK_S, _CHK_E
  15. ;
  16. ; Embedded COMCHK function, checksums the program image, and aborts to DOS
  17. ; if it does not match the previously calculated value.
  18. ;
  19. _CHK_S:    MOV        BX,0100h            ; Get offset of Command Tail
  20.         MOV        CX,BX                ; Save for later
  21.         MOV        AX,[SI]                ; Get first two bytes
  22.         MOV        [BX],AX                ; Replace it
  23.         MOV        AL,2[SI]            ; Get last byte
  24.         MOV        2[BX],AL            ; Replace it
  25.         XOR        AX,AX                ; Zero initial
  26. chk1:    ADD        AL,[BX]                ; Include low
  27.         ADC        AH,0                ; Include high
  28.         INC        BX                    ; Advance to next
  29.         CMP        BX,SI                ; At end?
  30.         JB        chk1                ; Do them all
  31.         CMP        AX,3[SI]            ; Does it match?
  32.         JNE        chk2                ; No, report error
  33. ; Passed... restore the original startup code, and execute it
  34.         JMP        CX
  35. ; Failed... Output error message & terminate
  36. chk2:    MOV        AH,40h                ; Write to file
  37.         MOV        BX,2                ; STDERR handle
  38.         MOV        CX,5[SI]            ; Get length
  39.         LEA        DX,7[SI]            ; Get message
  40.         INT        21h                    ; Output message
  41.         XOR        AH,AH                ; Terminate
  42.         INT        21h                    ; Goodbye
  43. _CHK_E:
  44. ;
  45. CSEG    ENDS
  46.         END
  47.